const multer = require('multer')

const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, './public/images')
    },
    filename: function (req, file, cb) {
        let name = file.originalname
        const index = name.lastIndexOf('.')
        const str = name.substring(0, index) + Date.now() + name.substring(index)
        cb(null, str)
    }
})

const upload = multer({ storage: storage })

module.exports = upload